package com.atguigu.spzx.product.mapper;

import com.atguigu.spzx.product.entity.Product;
import com.atguigu.spzx.product.entity.ProductSku;
import com.atguigu.spzx.product.vo.ProductSkuQueryReqVo;
import com.atguigu.spzx.product.vo.ProductSkuQueryRespVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * <p>
 * 商品sku Mapper 接口
 * </p>
 *
 * @author flyduck
 * @since 2023-11-04
 */
public interface ProductSkuMapper extends BaseMapper<ProductSku> {

    /**
     * 根据销量排序，获取前十条记录
     *
     * @return
     */
    List<ProductSku> getTop10ProductSkuListOrderBySaleNumDesc();

    /**
     * 分页查询
     *
     * @param pageParam
     * @param vo
     * @return
     */
    Page<ProductSkuQueryRespVo> getProductPageByQuery(@Param("pageParam") Page<Product> pageParam, @Param("vo") ProductSkuQueryReqVo vo);


    /**
     * 根据productId查询
     * @param productId
     * @return
     */
    default List<ProductSku> getProductSkuListByProductId(Long productId){
        QueryWrapper<ProductSku> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("product_id", productId);
        return this.selectList(queryWrapper);
    }

    default void updateSkuSaleNumBySkuId(Long skuId, Integer skuNum){
        ProductSku productSku = this.selectById(skuId);
        productSku.setSaleNum(skuNum);
        this.updateById(productSku);
    }
}
